package at.evonfc.view;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
import at.evonfc.bl.MenuUtils;
import at.evonfc.data.Cart;
import at.evonfc.listofdeviceswithnfc.R;

public class BorrowActivity extends Activity {
	public static final String ACTIVITY_NAME = "BORROW_ACTIVITY";
	
	public static final String RESERVE_MODE = "RESERVE_MODE";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_borrow);
		
		MainActivity.active_activity = BorrowActivity.ACTIVITY_NAME;
		
		Intent intent = getIntent();
		boolean reserve = intent.getBooleanExtra(BorrowActivity.RESERVE_MODE, false);

		TextView tvBorrowDevice = (TextView)findViewById(R.id.tvBorrowDevice);
		if(reserve) {
			tvBorrowDevice.setText(R.string.tv_reserveDevices);
			MainActivity.RESERVE_MODE = true;
		} else {
			tvBorrowDevice.setText(R.string.tv_borrowDevices);
			MainActivity.RESERVE_MODE = false;
		}
	}

	@Override
	protected void onResume() {
		super.onResume();
		MainActivity.active_activity = BorrowActivity.ACTIVITY_NAME;
	}
	
	@Override
	public void onBackPressed() {
		Intent intent = new Intent(this, HomeActivity.class);
		startActivity(intent);
	}

	public void onLogout(MenuItem item) {
		MenuUtils.getInstance().onLogout(this);
	}
	
	public void onCartClick(MenuItem item) {
		MenuUtils.getInstance().onCartClick(this);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    if(Cart.hasElements()) {
	    	inflater.inflate(R.menu.cart_new, menu);
	    } else {
	    	inflater.inflate(R.menu.cart_logout, menu);
	    }
	    return true;
	}
}
